#ifndef NR_DEVICE_H
#define NR_DEVICE_H

#include "nr_data.h"
#include "nr_device_type.h"

class nr_device_item;

enum nr_device_status_t
{
    NR_DEVICE_STATUS_STOPPED,
    NR_DEVICE_STATUS_PAUSED,
    NR_DEVICE_STATUS_STARTED
};

class nr_device_event
{
public:
    virtual nr_error_t on_child_starting(nr_device *chile_device) { return NR_ERROR_NOT_IMPLEMENTED; }
    virtual nr_error_t on_child_stopped(nr_device *chile_device) { return NR_ERROR_NOT_IMPLEMENTED; }
};

class nr_device_delegate
{
public:
    virtual void on_data_received(nr_data *data) = 0;
    virtual void on_event_report(nr_event *evt) = 0;
};

class nr_device : 
    public nr_object ,
    public nr_device_event
{
    Q_OBJECT
public:
    nr_device();
    
    virtual ~nr_device();

    void set_delegate(nr_device_delegate *delegate) { m_delegate = delegate; }

    virtual nr_error_t init(const QVariantHash &args) { return NR_ERROR_NOT_IMPLEMENTED; }

    virtual nr_error_t start();
    
    virtual nr_error_t stop();
    
    virtual nr_error_t on_child_starting(nr_device *chile_device) { return NR_ERROR_NOT_IMPLEMENTED; }

    virtual nr_error_t on_child_stopped(nr_device *chile_device);

    virtual nr_device_status_t status() { return m_status; }

    virtual nr_error_t set_property(nr_id_t prop_id, const QVariant &in_prop) { return NR_ERROR_NOT_IMPLEMENTED; }

    virtual nr_error_t get_property(nr_id_t prop_id, QVariant &out_prop) { return NR_ERROR_NOT_IMPLEMENTED; }
    
    virtual nr_error_t perform_action(nr_id_t action_id, const QVariantHash &in_params, QVariantHash &out_params) { return NR_ERROR_NOT_IMPLEMENTED; }

    virtual void add_child_device(nr_device *child_device);
    
    virtual void remove_child_device(nr_device *child_device);

    QList<nr_device *>& child_devices() { return m_child_device_list; }
    
    nr_device*& parent_device() { return m_parent_device; }

    nr_device_item*& device_item() { return m_device_item; }

    nr_error_t send_out_data(nr_data* data);
    
protected:
    nr_device_status_t m_status;
    nr_device_delegate *m_delegate;
    nr_device *m_parent_device;
    nr_device_item *m_device_item;
    QList<nr_device *> m_child_device_list;
};

#endif // NR_DEVICE_H
